package main

import (
	"crypto/md5"
	"fmt"
	"labix.org/v2/mgo"
	"labix.org/v2/mgo/bson"
)

func main() {
	session, err := mgo.Dial("127.0.0.1")
	if nil != err {
		fmt.Println("dial mgo fail!")
		return
	}
	defer session.Close()
	session.SetMode(mgo.Monotonic, true)
	collection := session.DB("bind").C("test")
	h := md5.New()
	str := "teststring"
	h.Write([]byte(str))
	hash := h.Sum(nil)
	mapp := make(map[string]string)
	mapp["str"] = str
	_, err = collection.Upsert(bson.M{"_id": hash}, mapp)
	if nil != err {
		fmt.Println("insert str fail!")
		return
	}
}
